package com.chinadaas.idcode.controller;

import com.chinadaas.custom.ChinaDaasDataEncoder;
import com.chinadaas.master.ChinaDaasDataDecoder;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Tian on 2017/10/10.
 */
@RestController
public class BaseController {
    @RequestMapping(value = "/getDecode",method = RequestMethod.GET)
    public Map getDecode(@RequestParam String id) throws Exception{
        id=id.replaceAll(" ","+"); //处理浏览器地址栏直接输入字符串包含加号时被转码
        String decode = ChinaDaasDataDecoder.decode(id);
        Map<String,String> result = new HashMap<>();
        result.put("decode",decode);
        return result;
    }
    @RequestMapping(value = "/getEncode",method = RequestMethod.GET)
    public Map getEncode(@RequestParam String code,@RequestParam String version) throws Exception{
        version = version.toUpperCase();
        String encode = ChinaDaasDataEncoder.encode(code, version);
        Map<String,String> result = new HashMap<>();
        result.put("encode",encode);
        return result;
    }
}
